//
//  SISSBaseTableView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/22.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSBaseTableView.h"

@implementation SISSBaseTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        
//        self.emptyDataSetSource = self;
//        self.emptyDataSetDelegate = self;
        
//        self.tableFooterView = [UIView new];
        [self setupSubviews];
        
        // 注册网络变化的监听事件
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChangedNotification:) name:kReachabilityChangedNotification object:nil];
        
    }
    return self;
}

#pragma mark - DZNEmptyDataSetSource,DZNEmptyDataSetDelegate
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    
    NSString *imageName = self.isNoNetwork ? @"网络" : @"空白";
    
    return  [UIImage imageNamed:imageName];
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *text = self.isNoNetwork ? @"糟糕~网络开小差了！" : @"";
    
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:12.0f],
                                 NSForegroundColorAttributeName: COLOR(0x8998A5)};
    
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (void)reachabilityChangedNotification:(NSNotification *)notification {
    
    NSLog(@"notification -> %@",notification.object);
    
    self.isNoNetwork = [notification.object intValue] == 0;
    [self reloadData];
}

- (void)dealloc {
    
    // 移除当前对象监听的事件
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)setupSubviews {
    
    
}


@end
